﻿using System;
using System.Collections.Generic;

namespace TypeCovariance
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("测试协变是否可以自动执行");
            TestStack<Dog> testStackDog = new TestStack<Dog>();
            //TestStack<Animal> testStackAnimal = testStackDog;

            TestStack<Animal> testStackAnimals = new TestStack<Animal>();
            //动物园清理员给动物洗澡
            ZooCleanerNoLimit.WashAnimal(testStackAnimals);

            ZooCleanerNoLimit.WashAnimal(testStackDog);

            IPopable<Animal> popableAnimal = testStackDog;

            ZooCleaner.Wash(testStackDog);

        }
    }

    public class Animal { };

    public class Cat : Animal { };

    public class Dog : Animal { };


    public interface IPopable<out T>
    {
        T Pop();
    }

    public class TestStack<T> : IPopable<T>
    {
        private T[] stackvalues = new T[100];
        private int index;

        public T Pop() => stackvalues[index--];

        public T PopValue() => stackvalues[index--];
        public void PushValue(T value) => stackvalues[++index] = value;
    }

    public class ZooCleanerNoLimit
    {
        public static void WashAnimal<T>(TestStack<T> washAnimals)
        {

        }
    }

    class ZooCleaner
    {
        public static void Wash<T>(IPopable<T> animals) where T : Animal
        {

         
        }
    }
}
